• China
• Russia
• Germany
• UK
• France
• Italy
• Iran
• Saudi Arabia
• Israel
• South Korea
• Military Expenditure Data - Stockholm International Peace Research Institute (SIPRI)
• Gross Domestic Product (GDP) Data - The World Bank (WBG)
# Data cleaning and data analysis
import pandas as pd
# Data visualization
import plotly as py
import plotly.graph_objects as go
import plotly.express as px
# Reading military spends data
mil_data= pd.read_excel("SIPRI-Milex-data-1949-2019.xlsx",
sheet_name = "Current USD",
skiprows = 5, index_col = "Country")
# Reading GDP data of countries
gdp_data = pd.read_csv("GDP2.csv", index_col = 1)
# Reading military share of GDP data
share_data = pd.read_excel("SIPRI-Milex-data-1949-2019.xlsx",
sheet_name = "Share of GDP",
skiprows = 5,index_col = "Country" )
# Reading military per capita data
milcap_data = pd.read_excel("SIPRI-Milex-data-1949-2019.xlsx",
sheet_name = "Per capita",
skiprows = 6,index_col = "Country")
# Reading GDP per capita data
gdpcap_data = pd.read_csv("GDPpercap.csv", index_col = 1)
# Reading Govt. spend for military data
govt_data = pd.read_excel("SIPRI-Milex-data-1949-2019.xlsx",
sheet_name = "Share of Govt. spending",
skiprows = 7,index_col = "Country")
# Check imported files
#mil_data.head()
#gdp_data.head()
#share_date.head()
#milcap_data.head()
#gdpcap_data.head()
#govt_data.head()
# Filtering military data by countries and years
mil_temp = mil_data.loc[["China", "UK", "Germany", "Russia", "France", "Italy", "Iran",
"Saudi Arabia", "Israel","Korea, South"],
[2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]]
# Renaming the columns
mil_temp.columns = ["Mil_2010", "Mil_2011","Mil_2012", "Mil_2013", "Mil_2014", "Mil_2015",
"Mil_2016", "Mil_2017","Mil_2018","Mil_2019"]
# Converting military spends from millions to billions
mil = round(mil_temp.astype(float)/1000,2)
mil
# Filtering GDP data by countries and years
gdp_temp = gdp_data.loc[["CHN", "GBR", "DEU", "RUS", "FRA", "ITA", "IRN", "SAU", "ISR", "KOR"],
["2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019"]]
# Adding country name column and setting it as the index
gdp_temp.insert(0,"Country",["China", "UK", "Germany", "Russia", "France", "Italy", "Iran",
"Saudi Arabia", "Israel", "Korea, South"],False)
gdp_temp2 = gdp_temp.reset_index(drop = True).set_index("Country")
# Renaming columns
gdp_temp2.columns = ["GDP_2010","GDP_2011","GDP_2012", "GDP_2013", "GDP_2014", "GDP_2015",
"GDP_2016", "GDP_2017","GDP_2018","GDP_2019"]
# Converting gdp spends from billions to trillions
gdp= round(gdp_temp2/1000000000000,2)
gdp
# Filtering GDP share data by countries and years
share_temp = share_data.loc[["China", "UK", "Germany", "Russia", "France", "Italy", "Iran",
"Saudi Arabia", "Israel", "Korea, South"],
[2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]]
# Renaming columns
share_temp.columns = ["Share_2010", "Share_2011","Share_2012", "Share_2013", "Share_2014",
"Share_2015", "Share_2016", "Share_2017", "Share_2018","Share_2019"]
# Converting shares into percentages
share = round(share_temp.astype(float)*100,2)
share
# Filtering military per capita data by countries and years
milcap_temp = milcap_data.loc[["China", "UK", "Germany", "Russia", "France", "Italy", "Iran",
"Saudi Arabia", "Israel", "Korea, South"],
[2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]]
# Renaming columns
milcap_temp.columns = ["Milcap_2010", "Milcap_2011","Milcap_2012", "Milcap_2013", "Milcap_2014",
"Milcap_2015", "Milcap_2016", "Milcap_2017", "Milcap_2018","Milcap_2019"]
milcap = round(milcap_temp.astype(float),2)
milcap
# Filtering GDP per capita data by countries and years
gdpcap_temp = gdpcap_data.loc[["CHN", "GBR", "DEU", "RUS", "FRA", "ITA", "IRN", "SAU", "ISR", "KOR"],
["2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019"]]
# Adding country name column and setting it as the index
gdpcap_temp.insert(0,"Country",["China", "UK", "Germany", "Russia", "France", "Italy", "Iran",
"Saudi Arabia", "Israel", "Korea, South"],False)
gdpcap_temp2 = gdpcap_temp.reset_index(drop = True).set_index("Country")
# Renaming columns
gdpcap_temp2.columns = ["GDPcap_2010","GDPcap_2011","GDPcap_2012", "GDPcap_2013", "GDPcap_2014",
"GDPcap_2015", "GDPcap_2016", "GDPcap_2017","GDPcap_2018","GDPcap_2019"]
gdpcap= round(gdpcap_temp2,2)
gdpcap
# Filtering govt. spends data by countries and years
gov_temp = govt_data.loc[["China", "UK", "Germany", "Russia", "France", "Italy", "Iran",
"Saudi Arabia", "Israel","Korea, South"],
[2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]]
# Renaming columns
gov_temp.columns = ["Gov_2010", "Gov_2011","Gov_2012", "Gov_2013", "Gov_2014",
"Gov_2015", "Gov_2016", "Gov_2017", "Gov_2018","Gov_2019"]
# Converting spends into percentages
gov = round(gov_temp.astype(float)*100,2)
gov
# Creating a master dataframe
df = pd.concat([mil,gdp,milcap,gdpcap,share,gov], axis = 1)
df
# Checking for null values
null_columns = df.columns[df.isnull().any()]
df[null_columns].isnull().sum()
df.info()
def plot1(x):
# Creating a loop to select military data from the master dataframe
for i in range(10):
yr = i + 2010
gdp = "GDP_" + str(yr)
mil = "Mil_" + str(yr)
plot1 = df[[gdp,mil]].copy()
# Plotting the data using scatter plot
fig = px.scatter(plot1, x = plot1[gdp], y = plot1[mil],size = plot1[gdp],
color = plot1.index, size_max = 60)
fig.update_traces(hovertemplate='GDP: %{x:$}T </br> </br> Mil: %{y:$}B')
fig.update_xaxes(title = "GDP ("+ str(yr) +")", range = [0,16],
tickprefix="$", ticksuffix="T")
fig.update_yaxes(title = "Military Expenditure (" + str(yr) + ")", range = [0,300],
tickprefix="$", ticksuffix="B")
fig.show()
plot1(plot1)
In this current list of countries, China accounts for the highest total GDP, as well as total military expenditure. This closely matches the country's economic growth and has also led to increasing annual military expenditure compared to its counterparts. Saudi Arabia has slowly increased its military expenditure over the years and has become the second highest spender in military along with Russia.
# Using melt function to select gdp share data yearwise
temp_share= share.copy().reset_index()
temp_share.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
plot2 = pd.melt(temp_share, id_vars = "Country")
# Plotting the data using bar chart
fig = px.bar(plot2, x = plot2["variable"], y = plot2["value"],
color = plot2["Country"], facet_col = plot2["Country"],
title = "Military Expenditure Share Of GDP")
fig.update_layout(height=400, width = 1000, template = 'plotly_white', showlegend = False)
fig.update_traces(hovertemplate = "Mil:%{y:.2f}%")
fig.update_xaxes(title = "2010 -'19", showticklabels = False)
fig.update_yaxes(title = "Military Share (%)",col = 1, ticksuffix="%")
fig.for_each_annotation(lambda a: a.update(text = a.text.split("=")[-1]))
fig.show()
However, the situation is quite different if we look at the military expenditure as a percentage share of the country's GDP. Saudi Arabia's military expenditure accounted the highest share of its GDP even with reduced military spends in the last few years. Similarly, Israel has comparatively spent a high share of GDP on its military expenses.
# Using melt function to select military data yearwise
temp_mil = mil.copy().reset_index()
temp_mil.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
plot3 = pd.melt(temp_mil,id_vars = ["Country"])
# Plotting data in an animated bar chart to show continuous yearwise transition
fig = px.bar(plot3, x = plot3["value"], y = plot3["Country"], color = plot3["Country"],
animation_frame = plot3["variable"],animation_group = plot3["Country"], range_x = [0,265])
fig.update_layout(height = 500, width = 900, template = 'plotly_white', showlegend = False)
fig.update_traces(hovertemplate = 'Mil:%{x:$}B')
fig.update_xaxes(title = "Military Spend (in Billions)", range= [0,300],
tickprefix="$", ticksuffix="B")
fig.show()
Over the last decade, China has significantly increased its military expenditure making it the second largest military spender in the world. Meanwhile Saudi Arabia has incrementally increased its military expenditure and is now at par with Russia.
def plot4(x):
# Creating a loop to select military and gdp per capita data from the master dataframe
for i in range(10):
yr = i + 2010
gdpcap = "GDPcap_" + str(yr)
milcap = "Milcap_" + str(yr)
plot4 = df[[gdpcap,milcap]].copy()
# Plotting the data using scatter plot
fig = px.scatter(plot4, x = plot4[gdpcap], y = plot4[milcap],
size = plot4[gdpcap], color = plot4.index, size_max = 60)
fig.update_traces(hovertemplate = 'GDP Per Cap: %{x:$} </br> </br> Mil Per Cap: %{y:$}')
fig.update_xaxes(title = "GDP Per Capita ("+ str(yr) + ")", range = [0,50000],
tickprefix="$")
fig.update_yaxes(title = "Military Per Capita (" + str(yr) + ")", range = [0,3000],
tickprefix="$", ticksuffix="k")
fig.show()
plot4(plot4)
Located in high conflict region, countries like Israel and Saudi Arabia have the highest military per capita expenditure compared to their counterparts despite having a smaller population size.
# Using melt function to military and gdp per capita data yearwise and adding a new percentage column
temp_milcap= milcap.copy().reset_index()
temp_gdpcap = gdpcap.copy().reset_index()
temp_milcap.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
temp_gdpcap.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
mcap_plot = pd.melt(temp_milcap, id_vars = "Country")
gcap_plot = pd.melt(temp_gdpcap, id_vars = "Country")
plot5 = pd.merge(mcap_plot,gcap_plot, on = mcap_plot.index, how = "left")
plot5["Per"] = round((plot5["value_x"]/plot5["value_y"])*100,2)
# Plotting the data using bar chart
fig = px.bar(plot5, x = plot5["variable_x"], y = plot5["Per"],
color = plot5["Country_x"], facet_col = plot5["Country_x"],
title = "Military Per Capita Expenditure To GDP Per Capita Expenditure")
fig.update_layout(height = 400, width = 1000, template = 'plotly_white', showlegend = False)
fig.update_traces(hovertemplate = "Mil Per Cap :%{y:.2f}%")
fig.update_xaxes(title = "2010 -'19", showticklabels = False)
fig.update_yaxes(title = "Military Per Capita (%)",col = 1, ticksuffix="%")
fig.for_each_annotation(lambda a: a.update(text = a.text.split("=")[-1]))
fig.show()
The same pattern follows in terms of percentage spend on military per capita compared to GDP per capita. Saudi Arabia has the highest military per capita expense followed by Israel and Russia. For rest of the countries, military per capita expense compared to GDP per capita has comparatively been low and stable.
# Using melt function to select govt. spends data yearwise
temp_gov = gov.copy().reset_index()
temp_gov.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
plot6 = pd.melt(temp_gov,id_vars=["Country"])
# Plotting the data using line chart
fig = px.line(plot6, x = plot6["variable"], y = plot6["value"], color = plot6["Country"],
labels = {"x": "","y": "Military Share (%)","color": "Country"},
title = "Military Share Of Govt. Spending", template = "ggplot2")
fig.update_traces(hovertemplate = 'Govt.Spend: %{y:.2f}%')
fig.update_xaxes(title = "")
fig.update_yaxes(title = "Military Share(%)", ticksuffix="%")
fig.show()
Government expenditure on military is usually higher in countries with warlike situations and here we see that Saudi Arabia has allocated a higher share of government expenditure on its military. Iran also follows a similar trend and is at second position, while rest of the countries have a steady government expenditure on the military.
# Calculating the average growth rate of military spending
tempmil = mil.copy()
def growth_rate(x):
total = []
for i in range(9):
yr = i + 2011
agr = ((tempmil["Mil_" + str(yr)] - tempmil["Mil_" + str(yr-1)])/tempmil["Mil_" + str(yr-1)])*100
total.append(agr)
return(round(sum(total)/9,2))
growth_rate(tempmil)
# Plotting the annual growth rate using bar chart
plot7 = pd.DataFrame(growth_rate(tempmil))
fig = go.Figure(data = [go.Bar(name = 'Annual Growth Rate', x = plot7.index, y = plot7[0])])
fig.update_layout(yaxis_title = "Growth Rate (%)", title = "Average Annual Military Expenditure Growth Rate",
template = "ggplot2")
fig.update_yaxes(title = "Military Share(%)", ticksuffix="%")
fig.update_traces(hovertemplate = '%{y:.2f}%', text = round(plot7[0],2) , textposition = "auto")
fig.show()
China's military expenditure growth rate is the highest due to its steady growing GDP and continuous investment in the military. Countries like Saudi Arabia, Israel and South Korea have also maintained similar growth rate. This increase in military expenditure by these countries is mainly because of the rising conflict with their neighboring regions. Whereas UK, France and Italy have reduced their military spends because of their slow GDP growth.
# Calculating year on year spending by each country
l=[]
def total(x):
for i in range(10):
yr = i+2010
l.append(plot3.loc[plot3["variable"] == yr,"value"].sum())
total(plot3)
# Poltting the data using stacked bar chart
fig = px.bar(plot3, x = plot3["variable"], y = plot3["value"], color = plot3["Country"],
color_discrete_sequence = px.colors.qualitative.Set2,
title = "Total Military Expenditure Over The Decade", template = "plotly_white")
fig.update_traces(hovertemplate = 'Mil: %{y:$}B',width = .7)
fig.update_xaxes(title = "")
fig.update_yaxes(title = "Military Spend (in Billion $)",tickprefix="$", ticksuffix="B")
fig.show()
Overall there has been a steady increase in military expenditure by these countries with a slight dip in 2015 & 2016 which could be due to slow economic growth during that period.
China has been the major contributor to this growth and has consistently been the highest spender among these nations. Saudi Arabia and Russia have also increased their military spends and are the second highest military spenders.
Regional Geopolitical situation which could possibly lead to a conflict has been the key driver for countries to invest more in this market.
Although the global military expenditure has been growing in the past few years, the unpredictable economic landscape caused due to Covid-19 pandemic could lead countries to reduce military budget and prioritize other pandemic responses & recovery projects in the coming years.